package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;

public class ReplaceParameterSqlHandler extends SqlParameterProcessor {


	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"REPLACE"});
	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter,List<SqlParameter> processors,SqlParameter sqlParameter) {
		String name = sqlParameter.getName();
		String value = parameter.getParameter(name);
		String defaultValue = sqlParameter.getValue();
		if (value == null && defaultValue != null) {
			value = defaultValue;
		}
		if (value == null) {
			value = "null";
		}
		sbSQL.append(value);
	}
	
	
}
